package struts.actionForm;

import javax.servlet.http.HttpServletRequest;

import metier.Etudiant;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class BeanEtudiant extends ActionForm {

	private static final long serialVersionUID = 1L;
	private Etudiant etudiant=new Etudiant();
	private String confirmMdp;
	
	public String getPrenom() {
		return etudiant.getPrenom();
	}
	public String getNom() {
		return etudiant.getNom();
	}
	public String getMdp() {
		return etudiant.getMdp();
	}
	public String getLogin() {
		return etudiant.getLogin();
	}
	public void setMdp(String mdp) {
		etudiant.setMdp(mdp);
	}
	public void setLogin(String login) {
		etudiant.setLogin(login);
	}
	public void setNom(String nom) {
		etudiant.setNom(nom);
	}
	public void setPrenom(String prenom) {
		etudiant.setPrenom(prenom);
	}
	
	public Etudiant getEtudiant() {
		return etudiant;
	}
	public void setEtudiant(Etudiant etudiant) {
		this.etudiant = etudiant;
	}
	
	public String getConfirmMdp() {
		return confirmMdp;
	}
	
	public void setConfirmMdp(String confirmMdp) {
		this.confirmMdp = confirmMdp;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
ActionErrors erreurs = new ActionErrors();
		
		if(this.getLogin() == null || this.getLogin().trim().equals("") 
			|| this.getMdp() == null || this.getMdp().trim().equals("")
			|| this.getConfirmMdp() == null || this.getConfirmMdp().trim().equals("")
			|| this.getNom() == null || this.getMdp().trim().equals("")
			|| this.getPrenom() == null || this.getPrenom().trim().equals(""))
			erreurs.add("Veuillez remplir TOUS les champs", new ActionMessage("beanEtudiant.erreur.champsvide"));
		
		if(!this.getMdp().equals(this.getConfirmMdp()))
			erreurs.add("Mauvais mdp", new ActionMessage("beanEtudiant.erreur.mauvais.mdp"));

		return erreurs;
	}
	
	
	
	

}
